package com.ltkj.shop.controller.mobile;

import com.ltkj.common.core.utils.bean.BeanUtils;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.web.page.TableDataInfo;
import com.ltkj.common.security.annotation.RequiresPermissions;
import com.ltkj.common.security.utils.DictUtils;
import com.ltkj.shop.domain.ShopRestMenuType;
import com.ltkj.shop.domain.ShopRestaurantMenu;
import com.ltkj.shop.domain.request.ShopRestMenuParams;
import com.ltkj.shop.domain.vo.DictDataVo;
import com.ltkj.shop.domain.vo.ShopRestMenuVo;
import com.ltkj.shop.service.IShopRestMenuTypeService;
import com.ltkj.shop.service.IShopRestaurantMenuService;
import com.ltkj.system.api.domain.SysDictData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 餐饮菜品移动端Controller
 * 
 * @author xupf
 * @date 2023-08-29
 */
@Api(tags = "餐饮菜品移动端接口")
@RestController
@RequestMapping("/mobile/restaurant/menu")
public class ShopRestMenuMobileController extends BaseController
{
    @Autowired
    private IShopRestaurantMenuService shopRestaurantMenuService;
    @Autowired
    private IShopRestMenuTypeService shopRestMenuTypeService;

    /**
     * 查询餐饮菜品列表
     */
    @ApiOperation("查询餐饮菜品列表")
    @GetMapping("/list")
    public TableDataInfo list(ShopRestMenuParams params)
    {
        startPage();
        // 查询上架菜单
//        shopRestaurantMenu.setStatus("1");
        ShopRestaurantMenu shopRestaurantMenu = new ShopRestaurantMenu();
        BeanUtils.copyBeanProp(shopRestaurantMenu, params);
        List<ShopRestaurantMenu> list = shopRestaurantMenuService.selectList(shopRestaurantMenu);
        List<ShopRestMenuVo> resList = list.stream().map(ShopRestMenuVo::fromDO).collect(Collectors.toList());
        return getDataTable(resList);
    }

    /**
     * 获取餐饮菜品详细信息
     */
    @ApiOperation("获取餐饮菜品详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopRestaurantMenuService.selectShopRestaurantMenuById(id));
    }

    /**
     * 获取菜品类型
     */
    @ApiOperation("获取菜品类型")
    @GetMapping("/searchType")
    public AjaxResult searchType()
    {
        List<SysDictData> list = DictUtils.getDictCache("shop_dish_type");
        List<DictDataVo> resList = list.stream().map(DictDataVo::fromDO).collect(Collectors.toList());
        return AjaxResult.success(resList);
    }

    /**
     * 获取菜品类型
     */
    @ApiOperation("获取菜品类型V2")
    @GetMapping("/searchType/{restId}")
    public AjaxResult searchType(@PathVariable("restId") Long restId)
    {
        ShopRestMenuType shopRestMenuType = new ShopRestMenuType();
        shopRestMenuType.setRestaurantId(restId);
        List<ShopRestMenuType> shopRestMenuTypes = shopRestMenuTypeService.selectShopRestMenuTypeList(shopRestMenuType);
        return AjaxResult.success(shopRestMenuTypes);
    }

}
